<template>
  <div :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
import { getBusinessOpportunities } from "@/api/region_jsc";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
const animationDuration = 3000;
const emphasisStyle = {
  itemStyle: {
    barBorderWidth: 1,
    shadowBlur: 10,
    shadowOffsetX: 0,
    shadowOffsetY: 0,
    shadowColor: "rgba(0,0,0,0.5)",
  },
};
export default {
  mixins: [resize],
  props: {
    listQuery: {
      type: Object,
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "350px",
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      showbtns: false,
      chart: null,
      xData: [],
      yData: [],
    };
  },

  mounted() {
    this.getList();
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
 methods: {
    
       getList() {
       
      getBusinessOpportunities(this.listQuery).then((res) => {
        this.xData = res.data.data.map(function (obj, index, array) {
          var rObj = [];
          rObj = obj.productTypeName;
          return rObj;
        });
        this.yData = res.data.data.map(function (obj, index, array) {
          var rObj2 = [];

          rObj2 = obj.contractAmount;
          return rObj2;
        });
        this.$nextTick(() => {
          this.initChart();
        });
      });
    },
    initChart() {
      let _self = this;
      this.chart = echarts.init(this.$el, "macarons");
      this.chart.setOption({
        // color: ["#ff89b0ff", "#ffcf5aff", "#6ef3edff",'#ab84fff','#52a8feff'],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        toolbox: {},
        legend: {
          left: "60",
          data: [
            "高校邦运营服务",
            "精品在线开放课程产品",
            "课程拍摄于制作服务",
            "高校邦学习平台",
            "平均"
          ],
        },
        xAxis: [
          {
             type: "category",
             axisTick:{
              show:false
            },
            data: this.xData,
            axisPointer: {
              type: "shadow",
            },
            axisLine: {
              lineStyle: {
                color: "#616266",
              },
            },
          },
        ],
          yAxis: [
          {
            type: "value",
             axisLine: {
                show:false,
              lineStyle: {
                color: "#616266",
              },
            },
            axisTick: {
              show: false,
            },
            name: "",
             nameTextStyle:{
          color: "#616266",
               },
            min: 0,
            // max: 2500,

             axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLabel: {
              formatter: "{value} 个",
              textStyle: {
                color: "#616266",
              },
            },
          },
          {
            type: "value",
            name: "",
             nameTextStyle:{
          color: "#616266",
               },
            min: 0,
            // max: 25,
            interval: 5,
             axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLabel: {
              formatter: "{value} 个",
              textStyle: {
                color: "#616266",
              },
            },
          },
        ],
        series: [
          {
            emphasis: emphasisStyle,
            name: "高校邦运营服务",
            type: "bar",
            barWidth:'60px',
            data: _self.yData,
          },
          {
            name: "精品在线开放课程产品",
            type: "bar",
            barWidth:'60px',
            data: _self.yData,
          },
          {
            name: "平均",
            type: "line",
            barWidth:'60px',
            symbolSize: 10,
            yAxisIndex: 1,
            data: _self.yData,
          },
          {
            name: "课程拍摄于制作服务",
            type: "bar",
barWidth:'60px',
            data: _self.yData,
          },
          {
            name: "高校邦学习平台",
            type: "bar",
barWidth:'60px',
            data: _self.yData,
          },
        ],
      });
    },
  },
};
</script>
